package cn.ljy.authority.config.verificationcode;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 验证码生成的图片配置
 */
@Configuration
public class KaptchaConfig {
    @Bean
    public Producer producer() {
        Properties properties = new Properties();
        // 验证码图片宽度
        properties.setProperty("kaptcha.image.width","150");
        // 验证码图片高度
        properties.setProperty("kaptcha.image.height","50");
        properties.setProperty("kaptcha.textproducer.char.string","0123456789");
        //文本集合，验证码值从此集合中获取
        //properties.setProperty("kaptcha.textproducer.char.string","ABCDEFGHIJKLMNOPQRSTUVWXYZ345679");
        //下面验证码容易混淆
        //properties.setProperty("kaptcha.textproducer.char.string","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        // 验证码的长度
        properties.setProperty("kaptcha.textproducer.char.length","5");
        //字体样式
        properties.put("kaptcha.textproducer.font.names","宋体,楷体,微软雅黑");
        // kaptcha.border 图片边框，合法值：yes , no yes
        //properties.setProperty("kaptcha.border","yes");
        // kaptcha.noise.color 干扰颜色，合法值： r,g,b 或者 white,black,blue. black
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(new Config(properties));
        return defaultKaptcha;
    }
}
